package top.laoshuzi.designpatterns.base.created.factory;

/**
 * 产品工厂
 */
public class ProductFactory {

    public static final int TYPE_PRODUCT_A = 1;
    public static final int TYPE_PRODUCT_B = 2;

    public static Product createProduct(int productType) {
        Product product = null;
        switch (productType) {
            case 1:
                product = new ProductA();
                product.setName("Product1");
                break;
            case 2:
                product = new ProductB();
                product.setName("Product2");
                break;
        }
        if (product == null)
            throw new NullPointerException("无效产品类型");
        return product;
    }
}
